package c.x.jy.service.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.Query;

import c.x.jy.dao.dao.OrderItemsDao;
import c.x.jy.dao.entity.OrderItemsEntity;
import c.x.jy.service.service.OrderItemsService;
import org.apache.commons.lang3.StringUtils;


@Service("orderItemsService")
public class OrderItemsServiceImpl extends ServiceImpl<OrderItemsDao, OrderItemsEntity> implements OrderItemsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        	QueryWrapper<OrderItemsEntity> query= 	 new QueryWrapper<OrderItemsEntity>() ;
    	if(params.get("searchKey")!=null&&params.get("searchValue")!=null&&!StringUtils.isEmpty(params.get("searchKey").toString())&&!StringUtils.isEmpty(params.get("searchValue").toString()))
    	    query.eq(  params.get("searchKey").toString(), params.get("searchValue"));
        if(params.get("businessId")!=null) 	query.eq("business_id", params.get("businessId"));
		if(params.get("orderId")!=null)query.eq("order_id",params.get("orderId"));
        IPage<OrderItemsEntity> page = this.page(
                new Query<OrderItemsEntity>().getPage(params),
                 query
        );

        return new PageUtils(page);
    }

	@Override
	public List<OrderItemsEntity> goodsByOrder(Long orderId) {
		QueryWrapper<OrderItemsEntity> query=new QueryWrapper<>();
		query.lambda().eq(OrderItemsEntity::getOrderId, orderId);
		return this.getBaseMapper().selectList(query );

	}


	@Override
	public List<OrderItemsEntity> selectListByOrderNo(Long orderId) {
		QueryWrapper<OrderItemsEntity> query=new QueryWrapper<>();;
		query.lambda().eq(OrderItemsEntity::getOrderId, orderId);
		return this.getBaseMapper().selectList(query);
	}

}
